<?php include('../includes/db_connect.php'); 
include('../includes/phpheader.php');
$id = $_POST["id"];

$vote = $_POST["vote"];

$otherName = $_POST["otherName"];
$otherPhone = $_POST["otherPhone"];
$otherLanguage = $_POST["otherLanguage"];
$otherOtherLanguage = $_POST["otherOtherLanguage"];
$otherLiving = $_POST["otherLiving"];

$dateMonth = $_POST["dateMonth"];
$dateDay = $_POST["dateDay"];
$dateYear = $_POST["dateYear"];
$date = $dateYear."-".$dateMonth."-".$dateDay; 

$birthDateMonth = $_POST["birthDateMonth"];
$birthDateDay = $_POST["birthDateDay"];
$birthDateYear = $_POST["birthDateYear"];
$birthDate = $birthDateYear."-".$birthDateMonth."-".$birthDateDay;

$age = $_POST["age"];
if(!$age) {
	$age=0;
}

$sex = $_POST["sex"];
$race = $_POST["race"];
$maritalStatus = $_POST["maritalStatus"];
$dependents = $_POST["dependents"];

if(strcmp($dependents,"0") == 0)
	$dependentsHowMany = 0;
else
	$dependentsHowMany = $_POST["dependentsHowMany"];
	
$birthplaceCity = $_POST["birthplaceCity"];
$birthplaceState = $_POST["birthplaceState"];
$citizen = $_POST["citizen"];

$ethnicity = $_POST["ethnicity"];
$primaryDisability = $_POST["primaryDisability"];
$secondaryDisability = $_POST["secondaryDisability"];
$primaryDisabilityType = $_POST["primaryDisabilityType"];
$secondaryDisabilityType = $_POST["secondaryDisabilityType"];
$congenital = $_POST["congenital"];
$traumatic = $_POST["traumaticInjury"];
$disease = $_POST["disease"];

$servicesDARS = $_POST["servicesDARS"];
$servicesTCB = $_POST["servicesTCB"];
$servicesMHMR = $_POST["servicesMHMR"];	
$servicesDHS = $_POST["servicesDHS"];
$servicesSchool = $_POST["servicesSchool"];
$servicesSSA = $_POST["servicesSSA"];	
$servicesHAHA = $_POST["servicesHAHA"];
$servicesTAN = $_POST["servicesTAN"];
$servicesOther = $_POST["servicesOther"];
	
$counselorName = $_POST["counselorName"];
$counselorNumber = $_POST["counselorNumber"];

$incomeJobs = $_POST["incomeJobs"];
$incomeSS = $_POST["incomeSS"];
$incomeSSI = $_POST["incomeSSI"];
$incomeSSDI = $_POST["incomeSSDI"];
$incomePublicAssistance = $_POST["incomePublicAssistance"];
$incomeClinicCard = $_POST["incomeClinicCard"];
$incomeWorkmansCompensation = $_POST["incomeWorkmansCompensation"];
$incomePension = $_POST["incomePension"];
$incomeMedicare = $_POST["incomeMedicare"];
$incomeMedicaid = $_POST["incomeMedicaid"];
$incomeUnemploymentBenefits = $_POST["incomeUnemploymentBenefits"];
$incomePrivateHealthInsurance = $_POST["incomePrivateHealthInsurance"];
	
//$transportationOption = $_POST["transportationOption"];
$transportationOption = 3;
$referralName = $_POST["referralName"];
$referralOther = $_POST["referralOther"];
$capSignoff = $_POST["capSignoff"];
$waiverILP = $_POST["waiverILP"];

if(!$congenital)	$congenital=0; 	else 	$congenital=1;
if(!$traumatic) 	$traumatic=0; 	else 	$traumatic=1;
if(!$disease) 		$disease=0; 		else 	$disease=1;

if(!$servicesDARS)		$servicesDARS=0; 		else 	$servicesDARS=1;
if(!$servicesTCB)			$servicesTCB=0; 		else 	$servicesTCB=1;
if(!$servicesMHMR)		$servicesMHMR=0; 		else 	$servicesMHMR=1;
if(!$servicesDHS)			$servicesDHS=0; 		else 	$servicesDHS=1;
if(!$servicesSchool)	$servicesSchool=0; 	else 	$servicesSchool=1;
if(!$servicesSSA)			$servicesSSA=0; 		else 	$servicesSSA=1;
if(!$servicesHAHA)		$servicesHAHA=0; 		else 	$servicesHAHA=1;
if(!$servicesTAN)			$servicesTAN=0; 		else 	$servicesTAN=1;
if(!$servicesOther)		$servicesOther=0; 	else 	$servicesOther=1;

if(!$incomeJobs)												$incomeJobs=0; 		else 	$incomeJobs=1;
if(!$incomeSS)													$incomeSS=0; 		else 	$incomeSS=1;
if(!$incomeSSI)													$incomeSSI=0; 		else 	$incomeSSI=1;
if(!$incomeSSDI)												$incomeSSDI=0; 		else 	$incomeSSDI=1;
if(!$incomePublicAssistance)						$incomePublicAssistance=0; 		else 	$incomePublicAssistance=1;
if(!$incomeClinicCard)									$incomeClinicCard=0; 		else 	$incomeClinicCard=1;
if(!$incomeWorkmansCompensation)				$incomeWorkmansCompensation=0; 		else 	$incomeWorkmansCompensation=1;
if(!$incomePension)											$incomePension=0; 		else 	$incomePension=1;
if(!$incomeMedicare)										$incomeMedicare=0; 		else 	$incomeMedicare=1;
if(!$incomeMedicaid)										$incomeMedicaid=0; 		else 	$incomeMedicaid=1;
if(!$incomeUnemploymentBenefits)				$incomeUnemploymentBenefits=0; 		else 	$incomeUnemploymentBenefits=1;
if(!$incomePrivateHealthInsurance)			$incomePrivateHealthInsurance=0; 		else 	$incomePrivateHealthInsurance=1;

if(!$capSignoff)				$capSignoff=0; 		else 	$capSignoff=1;

$employeeSignature = $_POST["employeeSignature"];
$consumerSiganture = $_POST["consumerSiganture"];

$eligibilitySignoff = $_POST["eligibilitySignoff"];
if(!$eligibilitySignoff) 	$eligibilitySignoff=0;  else 	$eligibilitySignoff=1;

$query = "select id from intake1 where consumer_id = ".$id;
if(mysql_fetch_array(mysql_query($query))) {
	$query = "update intake1 set voting = ".$vote.", date = '".$date."', other_contact = '".$otherName.
		"', other_contact_phone ='".$otherPhone."', other_language_needs = '".$otherLanguage."', other_other_language_needs = '".
		$otherOtherLanguage."', living_arrangement_id = ".
		$otherLiving.", dob='".$birthDate."', age = ".$age.", sex_id = ".$sex.", race_id = ".$race.", marital_status_id = ".
		$maritalStatus.", dependents = ".$dependents.", dependents_count = ".$dependentsHowMany.", birth_city = '".
		$birthplaceCity."', birth_state_id = ".$birthplaceState.", citizen = ".$citizen.", ethnicity = '".$ethnicity.
		"', primary_disability_id = ".$primaryDisability.", secondary_disability_id = ".$secondaryDisability.
		", primary_disability_type_id = ".$primaryDisabilityType.", secondary_disability_type_id = ".$secondaryDisabilityType.
		", congenital = ".$congenital.", traumatic = ".$traumatic.", disease = ".$disease.", employee_signature = '".
		$employeeSignature."', eligibility_signoff = '".$eligibilitySignoff."', consumer_signature = '".$consumerSiganture.		
		"', services_DARS = ".$servicesDARS.", services_MHMR = ".$servicesMHMR.", services_TCB = ".$servicesTCB.", services_DHS = ".
		$servicesDHS.	", services_School = ".$servicesSchool.", services_SSA = ".$servicesSSA.", services_HAHA = ".$servicesHAHA.
		", services_TAN = ".$servicesTAN.", services_Other = ".$servicesOther.", counselor_name = '".$counselorName.
		"', counselor_number = '".$counselorNumber."', income_Jobs = ".$incomeJobs.", income_SS = ".$incomeSS.
		", income_SSI = ".$incomeSSI.", income_SSDI = ".$incomeSSDI.", income_public_assistance = ".$incomePublicAssistance.
		", income_clinic_card = ".$incomeClinicCard.", income_workmans_compensation = ".$incomeWorkmansCompensation.
		", income_pension = ".$incomePension.", income_medicare = ".$incomeMedicare.", income_medicaid = ".$incomeMedicaid.
		", income_unemployment_benefits = ".$incomeUnemploymentBenefits.", income_private_health_insurance = ".
		$incomePrivateHealthInsurance.", transportation_option_id = ".$transportationOption.", referral_name = '".$referralName.
		"', referral_other = '".$referralOther."', cap_signoff=".$capSignoff.", waiverILP = ".$waiverILP.
		" where consumer_id = ".$id;
} else {
	$query = "insert into `intake1` (`consumer_id`, `id`, `voting`, `date`, `other_contact`, `other_contact_phone`, `other_language_needs`, `other_other_language_needs`, `living_arrangement_id`, `age`, `sex_id`, `race_id`, `marital_status_id`, `dependents`, `dependents_count`, `birth_city`, `birth_state_id`, `citizen`, `dob`, `ethnicity`, `primary_disability_id`, `secondary_disability_id`, `primary_disability_type_id`, `secondary_disability_type_id`, `congenital`, `traumatic`, `disease`, `employee_signature`, `eligibility_signoff`, `consumer_signature`, `services_DARS`, `services_TCB`, `services_MHMR`, `services_DHS`, `services_School`, `services_SSA`, `services_HAHA`, `services_TAN`, `services_Other`, `counselor_name`, `counselor_number`, `income_Jobs`, `income_SS`, `income_SSI`, `income_SSDI`, `income_public_assistance`, `income_clinic_card`, `income_workmans_compensation`, `income_pension`, `income_medicare`, `income_medicaid`, `income_unemployment_benefits`, `income_private_health_insurance`, `transportation_option_id`, `referral_name`, `referral_other`, `cap_signoff`, `waiverILP`) VALUES 
		(".$id.", ".$vote.", '".$date."', '".$otherName."', '".$otherPhone."', '".$otherLanguage."', '".
		$otherOtherLanguage."', ".$otherLiving.", ".$age.", ".$sex.", ".$race.", ".$maritalStatus.", ".$dependents.", ".
		$dependentsHowMany.", '".$birthplaceCity."', ".$birthplaceState.", ".$citizen.", '".$birthDate."','".$ethnicity."',".
		$primaryDisability.", ".$secondaryDisability.", ".$primaryDisabilityType.", ".$secondaryDisabilityType.
		", ".$congenital.", ".$traumatic.", ".$disease.", '".$employeeSignature."', ".$eligibilitySignoff.", '".$consumerSiganture.
		"', ".$servicesDARS.",".$servicesTCB.",".$servicesMHMR.",".$servicesDHS.",".$servicesSchool.",".$servicesSSA.",".$servicesHAHA.
		",".$servicesTAN.",".$servicesOther.",".$servicesDARS.", '".$counselorName."','".$counselorNumber."', ".$incomeJobs.
		",".$incomeSS.",".$incomeSSI.",".$incomeSSDI.",".$incomePublicAssistance.",".$incomeClinicCard.",".$incomeWorkmansCompensation.
		",".$incomePension.",".$incomeMedicare.",".$incomeMedicaid.",".$incomeUnemploymentBenefits.",".$incomePrivateHealthInsurance.",".
		$transportationOption.",'".$referralName."','".$referralOther."',".$capSignoff.",".$waiverILP."	);";
}

if(mysql_query($query)) {
  header("Location:../admin.php?action=cieedit&id=".$id."&Status=Intake 1 Form Submitted Successfully");
  exit();
  //echo "Success <br/>".$query;
} else {
  header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to process Intake 1 Form due to system error.  Please contact system administrator.");
  exit();
  //echo "Failure <br/>".$query;
}


